(function() {
	require(['jquery', 'echartsAll'], function(jquery, echartsAll) {
		/*禁止滚动条*/
		if($('li:first').hasClass('selected') == true){
			$('html').css('overflow','hidden');
			$('body').css('overflow','hidden');
		}else{
			$('html').css('overflow','scroll');
			$('body').css('overflow','hidden');
		}
		
		var userName = orange.getAppContext('USER')['username'];
		if(orange.getAppContext('USER')['username'] == 'gcs' || orange.getAppContext('USER')['username'] == 'czb'){
			$('.navbar-top:first').css('display','none');
		};
		
		new FullPage({
			id: 'pageContain',
			slideTime: 800,
			effect: {
				transform: {
					translate: 'Y'
				},
				opacity: [0, 1]
			},
			mode: 'wheel, touch, nav:navBar',
			easing: 'ease'
		});
		
		var w1 = Math.floor(document.getElementById('chinaMap').clientWidth);
		var w2 = Math.floor(document.getElementById('columnCharts').clientWidth);
		$('#chinaMap').css({'width':w1,'height':w1*0.9});
		$('#columnCharts').css({'width':w2*0.9,'height':w2*0.9});
		$('#chinaMap2').css({'width':w1,'height':w1*0.9});
		$('#columnCharts2').css({'width':w2*0.9,'height':w2*0.9});
		$('#chinaMap3').css({'width':w1,'height':w1*0.9});
		$('#columnCharts3').css({'width':w2*0.9,'height':w2*0.9});
		
		$('.map-chart').css('margin-top','85px');
		
		$.ajax({
			url: 'map/retrieveBarGraphMap.service',
			type: 'post',
			success: function(data) {
				var map = null;
				if(!data.success) {
					alert('提示', data.resultMsg); 
				} else {
					map = data.map;
					if(map.count == 0) {return;}
					bar(map.name, map.value);
					$.ajax({
						type:'post',
						url: "map/retrieveMapInfornation.service",
						data: {type: 5},
						success: function(data) {
							var map = null, mapData = [], len = 0, i=0;
							if(!data.success) {
								alert('提示', data.resultMsg); 
							} else {
								map = data.map;
								len = map.name.length;
								for(i=0; i<len; i++) {
									//删除澳门的测试数据
									if(map.name[i]== "新疆生产建设兵团") {
										continue;
									}
									if(map.value[i] == "1"){
										mapData.push({name: map.name[i], selected: true});
									} else if(map.value[i] == "0") {
										mapData.push({name: map.name[i], selected: false});
									}
								}
								chinaMap(mapData, '#C1232B');
							}
						}
					});
					$('#stateList').bind('click', {chinaMap: chinaMap}, function(evt) {
						var $span = $(evt.target), tagName = $span[0].tagName, 
							cls = $span.attr('class'), type= cls.charAt(cls.length - 1); 
						var data = evt.data, chinaMap = data.chinaMap;
						if(tagName != 'SPAN') {
							return;
						}
						$.ajax({
							type:'post',
							url: "map/retrieveMapInfornation.service",
							data: {type: type},
							success: function(data) {
								var map = null, mapData = [], len = 0, i=0,
									colorArray = ['#FCCE10','#E87C25','#27727B','#FE8463','#B5C334','#C1232B'];
								
								if(!data.success) {
									alert('提示', data.resultMsg); 
								} else {
									map = data.map;
									len = map.name.length;
									for(i=0; i<len; i++) {
										//删除澳门的测试数据
										if(map.name[i]== "新疆生产建设兵团") {
											continue;
										}
										if(map.value[i] == "1"){
											mapData.push({name: map.name[i], selected: true});
										} else if(map.value[i] == "0") {
											mapData.push({name: map.name[i], selected: false});
										}
									}
									chinaMap(mapData, colorArray[type]);
								}
							}
						});
					});
					
				}
			}
		});
		
		function chinaMap(mapData, color) {
			var myChart = echarts.init(document.getElementById("chinaMap")),
			    mapChart3 = echarts.init(document.getElementById("chinaMap3"));
			if(mapData == null) {
				mapData = [
		           {name: '北京',selected: true},{name: '天津',selected: false},{name: '上海',selected: false},{name: '重庆',selected: false},
		           {name: '河北',selected: false},{name: '河南',selected: false},{name: '云南',selected: false},{name: '辽宁',selected: false},
		           {name: '黑龙江',selected: false},{name: '湖南',selected: false},{name: '安徽',selected: false},{name: '山东',selected: false},
		           {name: '新疆',selected: false},{name: '江苏',selected: false},{name: '浙江',selected: false},{name: '江西',selected: false},
		           {name: '湖北',selected: false},{name: '广西',selected: false},{name: '甘肃',selected: false},{name: '山西',selected: false},
		           {name: '内蒙古',selected: false},{name: '陕西',selected: false},{name: '吉林',selected: false},{name: '福建',selected: false},
		           {name: '贵州',selected: false},{name: '广东',selected: false},{name: '青海',selected: false},{name: '西藏',selected: false},
		           {name: '四川',selected: false},{name: '宁夏',selected: false},{name: '海南',selected: false},{name: '台湾',selected: false},
		           {name: '香港',selected: false},{name: '澳门',selected: false}];
			}
			// 指定图表的配置项和数据
			var option = {
				    tooltip : {
				        trigger: 'item',
				        formatter: '{b}'
				    },
				    series : [
				        {
				            name: '中国',
				            type: 'map',
				            mapType: 'china',
				            selectedMode : 'single',
				            itemStyle:{
				                normal:{
				                	label:{show:true}
				                },
				                emphasis:{
				                	label:{show:true},
				                	areaStyle: { 
					            		color: color
					            	}
				                }
				            },
				            data:mapData,
				        }
				    ]
				};
			myChart.setOption(option);
			mapChart3.setOption(option);
		}
		
		function bar(xAxisData, yAxisData) {
			var myChart2 = echarts.init(document.getElementById('columnCharts')),
				myChart3 = echarts.init(document.getElementById('columnCharts3'));
		       
			var option2 = {
				    calculable: true,
				    grid: {
				        borderWidth: 0
				    },
				    xAxis: [
				        {
				            type: 'category',
				            show: false,
				            data: xAxisData
				        }
				    ],
				    yAxis: [
				        {
				            type: 'value',
				            show: false
				        }
				    ],
				    series: [
				        {
				            name: '全国各省申报状态',
				            type: 'bar',
				            itemStyle: {
				                normal: {
				                    color: function(params) {
				                        var colorList = [
				                          '#C1232B','#B5C334','#FCCE10','#E87C25','#27727B','#FE8463', '#26C0C0'
				                        ];
				                        return colorList[params.dataIndex];
				                    },
				                    label: {
				                        show: true,
				                        position: 'top',
				                        formatter: '{b}\n{c}'
				                    }
				                }
				            },
				            data: yAxisData,
				            markPoint: {
				                tooltip: {
				                    trigger: 'item',
				                    backgroundColor: 'rgba(0,0,0,0)'
				                },
				                data: [
				                    {xAxis:0, y: 350, name:xAxisData[0]},
				                    {xAxis:1, y: 350, name:xAxisData[1]},
				                    {xAxis:2, y: 350, name:xAxisData[2]},
				                    {xAxis:3, y: 350, name:xAxisData[3]},
				                    {xAxis:4, y: 350, name:xAxisData[4]},
				                    {xAxis:5, y: 350, name:xAxisData[5]}
				                ]
				            }
				        }
				    ]
				};
			myChart2.setOption(option2);
			myChart3.setOption(option2);
		}
       
	});
})();